import 'package:flutter/material.dart';
import 'package:flutter_wan_android/blocs/article_bloc.dart';
import 'package:flutter_wan_android/blocs/base/bloc_provider.dart';
import 'package:flutter_wan_android/blocs/project_bloc.dart';
import 'package:flutter_wan_android/ui/app_main.dart';

class NavigatorUtils {
  ///首页
  static goHome(BuildContext context) {
    Navigator.pushReplacementNamed(context, MainPage.sName);
  }

  static void push(BuildContext context, Widget widget) {
    Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context){
      return widget;
    }));

//    Navigator.push(context, PageRouteBuilder(pageBuilder: (context,
//        Animation<double> animation, Animation<double> secondaryAnimation) {
//      return widget;
//    },
//    transitionsBuilder: (context,Animation<double> animation,Animation<double> secondaryAnimation,Widget child){
//      return createTransition(animation, child);
//    }));
  }

  static void pushProject(BuildContext context, Widget widget) {
    Navigator.push(context,
        new MaterialPageRoute(builder: (BuildContext context) {
      return BlocProvider<ProjectBloc>(bloc: ProjectBloc(), child: widget);
    }));
  }

  static void pushArticle(BuildContext context, Widget widget) {
    Navigator.push(context,
        new MaterialPageRoute(builder: (BuildContext context) {
      return BlocProvider<ArticleBloc>(bloc: ArticleBloc(), child: widget);
    }));
  }

  static SlideTransition createTransition(
      Animation<double> animation, Widget child) {
    return new SlideTransition(
      position: new Tween<Offset>(
        begin: const Offset(1.0, 0.0),
        end: const Offset(0.0, 0.0),
      ).animate(animation),
      child: child,
    );
  }
}
